package com.zwj.controller;

import com.zwj.entity.UserEntity;
import com.zwj.service.StudentInfoService;
import com.zwj.utils.TokenUtils;
import com.zwj.vo.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
public class StudentInfoController {
    private final StudentInfoService studentInfoService;

    public StudentInfoController(StudentInfoService studentInfoService) {
        this.studentInfoService = studentInfoService;
    }

    @ApiOperation(value = "查询学生个人信息", notes = "查询学生个人信息")
    @GetMapping("/_s/queryStudentPersonalInfo")
    public Result queryStudentPersonalInfo(HttpServletRequest request) {
        UserEntity userEntity = TokenUtils.getUser(request);
        return studentInfoService.queryStudentPersonalInfo(userEntity.getId());
    }

    @ApiOperation(value = "查询学生邮箱信息", notes = "查询学生邮箱信息")
    @GetMapping("/_s/queryStudentEmail")
    public Result queryStudentEmail(HttpServletRequest request) {
        UserEntity userEntity = TokenUtils.getUser(request);
        return studentInfoService.queryStudentEmail(userEntity.getId());
    }

    @ApiOperation(value = "查询学生电话信息", notes = "查询学生电话信息")
    @GetMapping("/_s/queryStudentMobile")
    public Result queryStudentMobile(HttpServletRequest request) {
        UserEntity userEntity = TokenUtils.getUser(request);
        return studentInfoService.queryStudentMobile(userEntity.getId());
    }

    @ApiOperation(value = "修改学生邮箱", notes = "修改学生邮箱")
    @GetMapping("/_s/updateStudentEmail")
    public Result updateStudentEmail(String email,HttpServletRequest request) {
        UserEntity userEntity = TokenUtils.getUser(request);
        return studentInfoService.updateStudentEmail(email,userEntity.getId());
    }

    @ApiOperation(value = "修改学生电话", notes = "修改学生电话")
    @GetMapping("/_s/updateStudentMobile")
    public Result updateStudentMobile(String mobileNo,HttpServletRequest request) {
        UserEntity userEntity = TokenUtils.getUser(request);
        return studentInfoService.updateStudentMobile(mobileNo,userEntity.getId());
    }

    @ApiOperation(value = "查询实训小组信息", notes = "查询实训小组信息")
    @GetMapping("/_s/queryTrainingTeamInfo")
    public Result queryTrainingTeamInfo(HttpServletRequest request) {
        UserEntity userEntity = TokenUtils.getUser(request);
        return studentInfoService.queryTrainingTeamInfo(userEntity.getId());
    }

    @ResponseBody
    @ApiOperation(value = "上传头像", notes = "上传头像")
    @PostMapping(value = "/_s/uploadFile", headers = "content-type=multipart/form-data")
    public Result uploadFile(@RequestPart MultipartFile file) {
        return studentInfoService.uploadFile(file);
    }
}
